package com.test.daily.leetcode.y2022.m07.day0718.v06;

/**
 * @author Tom on 2022/7/18
 */
public class Solution {
    public static class Node{
        int value;
        public Node left;
        public Node right;
        public Node(int value){
            this.value = value;
        }
    }
    public boolean isBalance1(Node head){
        boolean[] ans = new boolean[1];
        process(head, ans);
        return ans[0];
    }
    public int process(Node head, boolean[] ans){
        if(ans[0] == false || head == null){
            return -1;
        }
        int leftHeight = process(head.left, ans);
        int rightHeight = process(head.right, ans);
        if(Math.abs(leftHeight - rightHeight) > 1){
            ans[0] = false;
        }
        return Math.max(leftHeight, rightHeight) + 1;
    }
    public static class Info{
        int height;
        boolean isBalance;
        public Info(){

        }
    }
}
